package com.njym.java.security.app.alipay;


import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 支付宝客户端配置
 * @author: zhy
 * @date: 2019/11/30 14:07
 */
@Configuration
@EnableConfigurationProperties(AliPayProperties.class)
public class AliPayConfiguration {

    private AliPayProperties aliPayProperties;

    public AliPayConfiguration(AliPayProperties properties) {
        this.aliPayProperties = properties;
    }

    /**
     * alipay-trade-java
     *
     * @return
     */
    @Bean
    public AlipayClient getAliClient() {
        return  new DefaultAlipayClient(
            aliPayProperties.getOpenApiDomain(),
            aliPayProperties.getAppid(),
            aliPayProperties.getPrivateKey(),
            "json",
            "UTF-8",
            aliPayProperties.getAlipayPublicKey(),
            "RSA2");
    }

}
